program ss
use gn_forward
implicit none
character*200 ndenfile,obsfile,dgfile,str
integer flag
integer nc
integer n_node,n_obs
real*8,allocatable::x_mod(:),y_mod(:),z_mod(:),den_mod(:)
real*8,allocatable::oee(:),onn(:),oele(:),grv(:),gerr(:)

integer,external::iargc

nc=iargc()

if(nc.ge.4) then
call getarg(1,ndenfile)
call getarg(2,obsfile)
call getarg(3,dgfile)
call getarg(4,str) ; read(str,*) flag
else
        write(*,*) "error parameter"
endif
write(*,*) "Start program ..."
!-----
call read_nden_nnd(ndenfile,n_node)
      allocate(x_mod(n_node),y_mod(n_node),z_mod(n_node),den_mod(n_node))
call read_nden_den(ndenfile,n_node,x_mod,y_mod,z_mod,den_mod)
!-----
call read_gloc_npt(obsfile,n_obs)
      allocate(oee(n_obs),onn(n_obs),oele(n_obs),grv(n_obs),gerr(n_obs))
call read_gloc_dat(obsfile,n_obs,oee,onn,oele)
!-----
call gn_forward(n_obs,oee,onn,oele,grv,n_node,x_mod,y_mod,z_mod,den_mod,flag)
      gerr=0.0
!-----
call write_gobs_sub(dgfile,n_obs,oee,onn,oele,grv,gerr)
write(*,*) "Finished program ..."
!-----
deallocate(x_mod,y_mod,z_mod,den_mod)
deallocate(oee,onn,oele,grv,gerr)
end program      
